package com.sgb.kjwl.view.ui.adapter.self.goods;

import android.content.Context;
import android.text.TextUtils;

import androidx.recyclerview.widget.LinearLayoutManager;

import com.sgb.kjwl.BR;
import com.sgb.kjwl.R;
import com.sgb.kjwl.databinding.ItemOperationRecordBinding;
import com.sgb.kjwl.model.entity.MemberPriceEntity;
import com.sgb.kjwl.model.entity.user.OperationRecordItemEntity;
import com.sgb.kjwl.model.entity.user.OperationRecordItemSkuEntity;
import com.sgb.kjwl.view.ui.adapter.map.AdapterOnItemClick;
import com.sgb.kjwl.view.ui.adapter.map.BaseRecycleAdapter;
import com.sgb.kjwl.view.ui.adapter.map.ItemViewHolder;
import com.swgk.core.util.DateUtils;

import java.util.ArrayList;
import java.util.List;

public class OperationRecodAdpater extends BaseRecycleAdapter<MemberPriceEntity.ItemMemberList> {
    private  ChoiceData lister;
    public OperationRecodAdpater(Context context) {
        super(context, R.layout.item_operation_record, new ArrayList<>());
    }

    @Override
    public void convert(ItemViewHolder holder, MemberPriceEntity.ItemMemberList operationRecordItemEntity) {
        holder.getmBinding().setVariable(BR.model, operationRecordItemEntity);
        if (holder.getmBinding() instanceof ItemOperationRecordBinding) {

            if(!TextUtils.isEmpty(operationRecordItemEntity.getCreateTime())){
                ((ItemOperationRecordBinding) holder.getmBinding()).tvSet.setText("更新时间："+ DateUtils.timestampTo13Date3(Long.valueOf(operationRecordItemEntity.getCreateTime())));
            }

            if (operationRecordItemEntity.getItemSkuMemberPriceList().size() > 0) {
                ((ItemOperationRecordBinding) holder.getmBinding()).recyclerview.setLayoutManager(new LinearLayoutManager(context));
                OperationRecodSonAdpater madpater = new OperationRecodSonAdpater(context,operationRecordItemEntity.getItemSkuMemberPriceList());
                ((ItemOperationRecordBinding) holder.getmBinding()).recyclerview.setAdapter(madpater);
                madpater.setOnItemClick(new AdapterOnItemClick<MemberPriceEntity.SkuMemberPriceList>() {
                    @Override
                    public void onItemClick(MemberPriceEntity.SkuMemberPriceList skuMemberPriceList, int position) {
                        if(lister!=null){
                            lister.ClickData(skuMemberPriceList,position,operationRecordItemEntity);
                        }
                    }
                });
            }


        }
    }

    /**
     * 设置详情点击事件回调
     * @param lister
     */
    public void setLister(ChoiceData lister) {
        this.lister = lister;
    }

    public interface ChoiceData{
        public void ClickData(MemberPriceEntity.SkuMemberPriceList data,int position,MemberPriceEntity.ItemMemberList mdata);
    }
}
